home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / printfx / cst.a < prev    next >
Text File  |  1989-06-08  |  4KB  |  185 lines

  1. *
  2. * C initial startup procedure under AmigaDOS
  3. * Special stripped version !!
  4.  
  5.     INCLUDE    "exec/types.i"
  6.     INCLUDE    "exec/libraries.i"
  7.     INCLUDE    "libraries/dos.i"
  8.     INCLUDE    "libraries/dosextens.i"
  9.     INCLUDE    "exec/funcdef.i"
  10.     INCLUDE    "exec/exec_lib.i"
  11.     INCLUDE    "libraries/dos_lib.i"
  12.  
  13. AbsExecBase    EQU    4
  14.  
  15.     xdef    _XCEXIT        exit(code) is standard way to leave C.
  16.  
  17.     xref    _LinkerDB    linker defined base value
  18.     xref    __BSSBAS    linker defined base of BSS
  19.     xref    __BSSLEN    linker defined length of BSS
  20.  
  21.     csect    text,0,0,1,2    any xref's after this are 16-bit reloc
  22.  
  23.     xref    __main        Name of C program to start with.
  24.  
  25. start:
  26.     movem.l d1-d6/a0-a6,-(a7)
  27. REGSIZE    EQU    (6+7)*4
  28.     lea    REGSIZE(a7),A5        determine old stack pointer
  29.     move.l    a0,a2            save command pointer
  30.     move.l    d0,d2            and command length
  31.     lea    _LinkerDB,a4        load base register
  32.  
  33.     lea    __BSSBAS,a0        get base of BSS
  34.     moveq    #0,d1
  35.     move.l    #__BSSLEN,d0        get length of BSS in longwords
  36.     bra.s    clr_lp            and clear for length given
  37. clr_bss move.l    d1,(a0)+
  38. clr_lp    dbf    d0,clr_bss
  39.  
  40.     move.l    AbsExecBase.W,a6
  41.     move.l    a6,_SysBase(A4)
  42.     move.l    a7,__StackPtr(A4)    Save stack ptr
  43.  
  44. *------ get the address of our task
  45.     suba.l    a1,a1
  46.     jsr    _LVOFindTask(a6)
  47.     move.l    d0,a3
  48.  
  49. *------ are we running as a son of Workbench?
  50.     move.l    pr_CurrentDir(A3),_curdir(A4)
  51.     tst.l    pr_CLI(A3)
  52.     beq    exit4            Not supported
  53.  
  54.     move.l    a5,D0            Get top of stack
  55.     sub.l    4(a5),D0        compute bottom 
  56.     move.l    D0,__base(A4)        save for stack checking
  57.  
  58. *------ attempt to open DOS library:
  59.     lea    DOSName(pc),A1
  60.     moveq.l    #0,D0
  61.     jsr    _LVOOpenLibrary(a6)
  62.     move.l    D0,_DOSBase(A4)
  63.     bne.s    DOSok
  64.     moveq.l    #100,d0
  65.     bra.s    exit2
  66. DOSok
  67. *------ find command name:
  68.     move.l    pr_CLI(a3),a0
  69.     add.l    a0,a0            bcpl pointer conversion
  70.     add.l    a0,a0
  71.     move.l    cli_CommandName(a0),a1
  72.     add.l    a1,a1            bcpl pointer conversion
  73.     add.l    a1,a1
  74.  
  75. *------ collect parameters:
  76.     move.l    d2,d0            get command line length
  77.     moveq.l    #0,d1
  78.     move.b    (a1)+,d1
  79.     move.l    a1,__ProgramName(A4)
  80.     add.l    d1,d0            add length of command name
  81.     addq.l    #1,d0            allow for space after command 
  82.  
  83.     clr.w    -(A7)            set null terminator for command line
  84.     addq.l    #1,D0            force to even number of bytes
  85.     andi.w    #$fffe,D0        *(round up)
  86.     sub.l    D0,A7            make room on stack for command line
  87.     subq.l    #2,D0
  88.     clr.w    0(A7,D0)
  89.  
  90. *------ copy command line onto stack
  91.     move.l    d2,d0            get command line length
  92.     subq.l    #1,d0
  93.     add.l    d1,d2
  94.  
  95. copy_line:
  96.     move.b    0(A2,D0.W),0(A7,D2.W)    copy command line to stack
  97.     subq.l    #1,d2
  98.     dbf    d0,copy_line
  99.     move.b    #' ',0(a7,d2.w)        add space between command and parms
  100.     subq.l    #1,d2
  101.  
  102. copy_cmd:
  103.     move.b    0(a1,d2.w),0(a7,d2.w)    copy command name to stack
  104.     dbf    d2,copy_cmd
  105.     move.l    A7,A1
  106.     move.l    A1,-(A7)        push command line address
  107.  
  108.     lea.l    Asterix(pc),a0
  109.     move.l    a0,d1
  110.     move.l    #MODE_OLDFILE,d2
  111.     move.l    _DOSBase(A4),a6
  112.     jsr    _LVOOpen(a6)
  113.     move.l    d0,_ConOut(a4)
  114.     beq.s    exit4
  115.  
  116. main    jsr    __main(PC)        call C entrypoint
  117. *    moveq.l #0,d0            set successful status
  118.     bra.s    exit2
  119.  
  120.  
  121. _XCEXIT:
  122.     move.l    4(SP),d0        extract return code
  123. exit2:
  124.     move.l    d0,-(a7)
  125.     move.l    __ONEXIT(A4),d0        exit trap function?
  126.     beq.s    exit3
  127.     move.l    d0,a0
  128.     jsr    (a0)
  129.  
  130. exit3    move.l    _ConOut(a4),d1
  131.     move.l    _DOSBase(A4),a6
  132.     jsr    _LVOClose(a6)
  133.  
  134. exit4    move.l    AbsExecBase.W,a6
  135.     move.l    _DOSBase(A4),a1
  136.     jsr    _LVOCloseLibrary(a6)    close Dos library
  137.  
  138. exitToDOS:
  139.     move.l    (a7)+,d0
  140.     movea.l    __StackPtr(a4),SP    restore stack ptr
  141.     movem.l    (a7)+,d1-d6/a0-a6
  142.     rts
  143.  
  144. DOSName    dc.b    'dos.library',0
  145. Asterix    dc.b    '*',0
  146.  
  147. *-----------------------------------------------------------------------
  148.  
  149.     csect    __MERGED,1,,2,2
  150.  
  151.     xref    _DOSBase
  152.  
  153.     xdef    _SysBase,_LoadAddress
  154.     xdef    _curdir,__mbase,__mnext,__msize,__tsize
  155.     xdef    __oserr,__OSERR,__FPERR,__SIGFPE,__ONERR,__ONEXIT,__ONBREAK
  156.     xdef    __SIGINT,__ECS
  157.     xdef    __ProgramName,__StackPtr,__base
  158.     xdef    _ConOut
  159.  
  160. _ConOut        ds.l    1
  161. __base        ds.l    1        base of stack
  162. __mbase        ds.l    1        base of memory pool
  163. __mnext        ds.l    1        next available memory location
  164. __msize        ds.l    1        size of memory pool
  165. __tsize        ds.l    1        total size?
  166. __oserr        equ    *
  167. __OSERR        ds.l    1
  168. __FPERR        ds.l    1
  169. __SIGFPE    ds.l    1
  170. __SIGINT    ds.l    1
  171. __ONERR        ds.l    1
  172. __ONEXIT    ds.l    1
  173. __ONBREAK    ds.l    1
  174. __ECS        ds.l    1        extended character set flag
  175. _curdir        ds.l    1
  176. _console_dev    ds.l    1
  177. _SysBase    ds.l    1
  178. _LoadAddress    ds.l    1        program load address
  179. __StackPtr    ds.l    1
  180. __ProgramName    ds.l    1
  181.  
  182.     END
  183.     
  184.